'use strict';
const moment = require('moment')

module.exports = app => {
  const { STRING, INTEGER, DATE, ENUM, BIGINT } = app.Sequelize;
  const User = app.model.define('user', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true, unique:true },
    name: STRING(30),
    age: {
      type:INTEGER,
      min:0,
      max:200
    },
    mobile:{
        type:STRING(11),
        allowNull:false,
        unique:true
    },
    sex:{
        type:ENUM,
        allowNull:false,
        values:['male','fomale','undefine']
    },
    nickname:STRING,
    created_at: {
      type:BIGINT(13),
      allowNull:false,
      defaultValue:new Date().getTime(),
      // set(val){
      //   console.log(val+"ssssssssssss")
      //   console.log("______________"+new Date().getTime())
      //   this.setDataValue('created_at',new Date().getTime())
      // },
    get(){
      let val = this.getDataValue("created_at")
      return moment(val).format('YYYY年MM月DD日 hh:mm:ss')
    }
    },
    updated_at: DATE,
  },{
    timestamps: false,
    createdAt: false,
    sequelize:app.Sequelize
  });

  return User;
};